﻿#region using
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
#endregion

namespace XmlGenSharp.Logic.Main
{
  public class CompoundGenerator : GeneratorBase
  {
    // Constructors

    #region CompoundGenerator()
    public CompoundGenerator() : this(string.Empty, "NotSpecified")
    {
    }
    #endregion

    #region CompoundGenerator(string inputFileName, string defaultNamespace)
    public CompoundGenerator(string inputFileName, string defaultNamespace)
      : base(inputFileName, defaultNamespace)
    {
    }
    #endregion

    // Public Properties

    #region InnerGenerators
    public IList<IGenerator> InnerGenerators
    {
      get
      {
        if (_innerGenerators == null)
          _innerGenerators = new List<IGenerator>();

        return _innerGenerators;
      }
    }
    private IList<IGenerator> _innerGenerators = null;
    #endregion

    #region Namespace
    public string Namespace
    {
      get
      {
        return (_namespace == null) ? DefaultNamespace : _namespace;
      }
      set
      {
        _namespace = value;
      }
    }
    private string _namespace = null;
    #endregion

    // Public Methods

    #region Generate(IGeneratorContext cx)
    public override void Generate(IGeneratorContext cx)
    {
      cx.Writer.Write(PreText);

      foreach (IGenerator generator in InnerGenerators)
        generator.Generate(cx);

      cx.Writer.Write(PostText);
    }
    #endregion

    #region GetFileName()
    public override string GetFileName()
    {
      return null;
    }
    #endregion

    #region Add(IGenerator generator)
    public void Add(IGenerator generator)
    {
      InnerGenerators.Add(generator);
    }
    #endregion
  }
}
